﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using Microsoft.ApplicationBlocks.Data;
using System.Collections;


namespace VideoWorld.DataAccess
{
    public class Videos
    {
        //从数据库里取出推荐影片
        public static DataSet GetRecommendVideos()
        {
            DataSet RecommendVideos = SqlHelper.ExecuteDataset(ConfigurationSettings.AppSettings["ConnectionString"], CommandType.StoredProcedure, "GetRecommendMovFile");
            return RecommendVideos;
        }

        //显示选择影片的详细信息
        public static ArrayList GetVideoInfo(string ID, ArrayList videoInfo)
        {
            SqlDataReader VideoInfoReader = SqlHelper.ExecuteReader(ConfigurationSettings.AppSettings["ConnectionString"].ToString(), CommandType.StoredProcedure, "GetVideoInfo", new SqlParameter("@ID", ID));
            while (VideoInfoReader.Read())
            {
                videoInfo.Add(VideoInfoReader["Name"]);
                videoInfo.Add(VideoInfoReader["FileType"]);
                videoInfo.Add(VideoInfoReader["Author"]);
                videoInfo.Add(VideoInfoReader["Performer"]);
                videoInfo.Add(VideoInfoReader["Maker"]);
                videoInfo.Add(VideoInfoReader["Language"]);
                videoInfo.Add(ConfigurationSettings.AppSettings["FilePath"].ToString() + VideoInfoReader["Image"].ToString());
                videoInfo.Add(VideoInfoReader["Summary"]);
            }
            VideoInfoReader.Close();
            return videoInfo;
        }
        //在后台显示所有影片类型
        public static DataSet SerachVideoTypeData()
        {
            DataSet dataSetVideoTypes = SqlHelper.ExecuteDataset(ConfigurationSettings.AppSettings["ConnectionString"], CommandType.StoredProcedure, "GetVideoType");
            return dataSetVideoTypes;
        }
        //添加影片类型
        public static int AddVideoType(string videoTypeName, string videoTypeSummary)
        {
            SqlParameter[] sparam = new SqlParameter[3];
            sparam[0] = new SqlParameter("@Name", videoTypeName);
            sparam[1] = new SqlParameter("@Summary", videoTypeSummary);
            sparam[2] = new SqlParameter("@Result", SqlDbType.Int);
            sparam[2].Direction = ParameterDirection.Output;
            SqlHelper.ExecuteNonQuery(ConfigurationSettings.AppSettings["ConnectionString"], CommandType.StoredProcedure, "AddVideoType", sparam);
            return Convert.ToInt32(sparam[2].Value);
        }
        //更新影片类型
        public static int UpdateVideoType(string videoTypeID, string videoTypeName, string videoTypeSummary)
        {
            SqlParameter[] sparam = new SqlParameter[4];
            sparam[0] = new SqlParameter("@ID", videoTypeID);
            sparam[1] = new SqlParameter("@Name", videoTypeName);
            sparam[2] = new SqlParameter("@Summary", videoTypeSummary);
            sparam[3] = new SqlParameter("@Result", SqlDbType.Int);
            sparam[3].Direction = ParameterDirection.Output;
            SqlHelper.ExecuteNonQuery(ConfigurationSettings.AppSettings["ConnectionString"], CommandType.StoredProcedure, "UpdateVideoType", sparam);
            return Convert.ToInt32(sparam[3].Value);
        }
        //删除影片类型
        public static int DeleteVideoType(string videoTypeID)
        {
            SqlParameter[] sparam = new SqlParameter[2];
            sparam[0] = new SqlParameter("@ID", videoTypeID);
            sparam[1] = new SqlParameter("@Result", SqlDbType.Int);
            sparam[1].Direction = ParameterDirection.Output;
            SqlHelper.ExecuteNonQuery(ConfigurationSettings.AppSettings["ConnectionString"], CommandType.StoredProcedure, "DeleteVideoType", sparam);
            return Convert.ToInt32(sparam[1].Value);
        }
    }
}
